package com.cskaoyan.user.service.impl.zyl_impl;

import com.cskaoyan.mall.commons.result.ResponseData;
import com.cskaoyan.user.dal.entitys.Member;
import com.cskaoyan.user.dal.entitys.UserVerify;
import com.cskaoyan.user.dal.persistence.MemberMapper;
import com.cskaoyan.user.dal.persistence.UserVerifyMapper;
import com.cskaoyan.user.form.UserRegisterRequest;
import com.cskaoyan.user.form.UserVerifyRequest;
import com.cskaoyan.user.service.IUserRegisterService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import static com.cskaoyan.mall.commons.constant.SysRetCodeConstants.KAPTCHA_CODE_ERROR;

@Slf4j
@Service
public class zyl_IUserRegisterServiceImpl implements zyl_IUserRegisterService {
    @Autowired
    UserVerifyMapper userVerifyMapper;

    @Autowired
    MemberMapper memberMapper;


    @Override
    public void register(UserRegisterRequest request) {

    }

    @Override
    public ResponseData verify(UserVerifyRequest request) {
        ResponseData responseData = new ResponseData();
        UserVerify userVerify1 = new UserVerify();
        userVerify1.setUsername(request.getUsername());
        userVerify1.setUuid(request.getUuid());
        List<UserVerify> select = userVerifyMapper.select(userVerify1);
        if (select.size() == 0 ) {
            responseData.setCode(KAPTCHA_CODE_ERROR.ordinal());
            responseData.setMessage("验证失败！");
            return responseData;
        }
        userVerify1.setIsVerify("Y");
        userVerify1.setId(select.get(0).getId());
        userVerifyMapper.updateByPrimaryKeySelective(userVerify1);
        Member member = new Member();
        member.setUsername(request.getUsername());
        List<Member> select1 = memberMapper.select(member);
        member.setId(select1.get(0).getId());
        member.setIsVerified("Y");
        memberMapper.updateByPrimaryKeySelective(member);
        responseData.setCode(200);
        responseData.setMessage("成功!");
        return responseData;
    }

}


